<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
	<link rel="stylesheet" href="../../css/bootstrap.min.css">
	<script src="../../js/jquery/jquery.min.js"></script>
	<script src="../../js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
	<script src="../../js/jquery.validation/1.14.0/messages_zh.min.js"></script>
	<style>
		input.error{
			border: 1px solid #E6594E;
		}
	</style>
</head>
<body>
	 
	 <div class="container">     
          <form id="addbuysForm">
                  <h4>
                  申请人：${Session.oauser.userUsername}<br><br>
                  申购部门：${Session.oauser.oaDept.deptName}<br><br>          
                   申请日期：<input type="text" name="buyDate" id="buyDate" value ="${.now?date}" readonly="readonly" style="border:none"><br>
               <br></h4>
		  <div class="form-group">
			<label for="buyName">物品名称：</label>
			<input type="text" class="form-control" id="buyName" name="buyName" placeholder="输入物品名称">
		  </div>
		  
		  <div class="form-group">
			<label for="buyNumber">数量：</label>
			<input type="text" class="form-control" id="buyNumber" name="buyNumber" placeholder="输入数量">
		  </div>
		  
		  <div class="form-group">
			<label for="buyPrice">单价：</label>
			<input type="text" class="form-control" id="buyPrice" name="buyPrice" placeholder="输入单价">
		  </div>
		  
		
		  
		  <div class="form-group">
			<label for="buyUseDate">需求时间：</label>
			<input type="text" class="form-control" id="buyUseDate" name="buyUseDate" placeholder="输入需求时间">
		  </div>

		  <div class="form-group">
			<label for="buyUse">用途：</label>
			<input type="text" class="form-control" id="buyUse" name="buyUse" placeholder="输入用途">
		  </div>
		  
		<input type="hidden" name="oaDept.deptId" id="deptid" value ="${Session.User.oaDept.deptId}">
        <input type="hidden" name="oaUser.userId" id="userid" value ="${Session.User.userId}">
        <input type="hidden" name="oaSubmit.submitId" id="submitid"value ="1">
		  
		<div class="form-group">
		  <button type="button" id="saveBtn" class="btn btn-success">提交</button>
		  <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
		</div>
		
		</form>
		
    </div>
    
    <script>
    
    var addBuys = function(){
    
		if(!check().form()){ 
			return;  	
		}
		$.ajax({
			   type: "GET",
			   dataType: "json",
			   url: "/OaBuy/addbuy",
			   data: {
					"buyName": $("#buyName").val(),
					"buyNumber": $("#buyNumber").val(),
					"buyPrice": $("#buyPrice").val(),
					"buyUse": $("#buyUse").val(),
					"buyDate": $("#buyDate").val(),
					"buyUseDate": $("#buyUseDate").val(),
					"oaDept.deptId": $("#deptid").val(),
					"oaSubmit.submitId": $("#submitid").val(),
					"oaUser.userId": $("#userid").val(),
			   },
			   success: function(msg){
				   alert(1);
					$('#cancelBtn').click();			
			   }
		});
	}
	
	$('#saveBtn').on('click', function(){
		addBuys();
		
	});
	
	$('#cancelBtn').on('click', function(){
		var index = parent.layer.getFrameIndex(window.name);
		parent.getUserPageList();
		parent.layer.close(index);
	});
    
    
    
    校验字段是否正确 
    function check(){ 
        /*返回一个validate对象，这个对象有一个form方法，返回的是是否通过验证*/ 
        return $("#addbuysForm").validate({ 
                    rules:{ 
                    	
                    	buyName:{ 
                            required:true
                        },
                        buyNumber:{ 
                            required:true
                        },
                        buyPrice:{ 
                            required:true
                        },
                        buyUse:{ 
                            required:true
                        },
                    	buyUseDate:{ 
                            required:true
                        },
                       
                    }, 
                    messages:{ 
                    	buyName:{ 
                            required:""
                        },
                        buyNumber:{ 
                            required:""
                        },
                        buyPrice:{ 
                            required:""
                        },
                        buyUse:{ 
                            required:""
                        },
                    	buyUseDate:{ 
                            required:""
                        },
                    }     
                }); 
    } 
    
   
    
    </script>
</body>
</html>